{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "794e6c5f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0  1  2  3  4  5  6  7  8  9 10 11]\n"
     ]
    }
   ],
   "source": [
    "# 初识\n",
    "import numpy as np\n",
    "a = np.arange(12)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c4c3d620",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.2718648910522461\n",
      "0.0020012855529785156\n"
     ]
    }
   ],
   "source": [
    "# 性能对比\n",
    "\n",
    "# 原生\n",
    "import time\n",
    "t1=time.time()\n",
    "arr = []\n",
    "for x in range(1000000):\n",
    "    arr.append(x**2)\n",
    "t2=time.time()\n",
    "print(t2-t1)\n",
    "\n",
    "# numpy\n",
    "t3=time.time()\n",
    "b=np.arange(1000000)**2\n",
    "t4=time.time()\n",
    "print(t4-t3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "059a5313",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4]\n",
      "['1' '2' '3' '4']\n",
      "['1' '2' '3' '4']\n",
      "<class 'numpy.ndarray'>\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# 创建数组\n",
    "arr1 = np.array([1,2,3,4])\n",
    "print(arr1)\n",
    "\n",
    "arr2 = np.array([1,'2',3,4])\n",
    "print(arr2)\n",
    "\n",
    "arr3 = np.array([1,\"2\",3,4])\n",
    "print(arr3)\n",
    "\n",
    "print(type(arr3))\n",
    "print(arr3[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "6c26b508",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.04810084 0.69193157]]\n",
      "0.04810084144009008\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr4 = np.random.random((1,2))\n",
    "print(arr4)\n",
    "print(arr4[0,0])\n",
    "type(arr4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
